<?php

namespace app\common\model;

use think\facade\Request;
use think\Model;
use think\model\concern\SoftDelete;

class Apply extends Model
{
    use SoftDelete;
    //
    public function getProject()
    {
        return $this->hasOne('project','id','project_id');
    }

    public function getUser(){
        return $this->hasOne('users','id','user_id');
    }

    public function getStatusAttr($value)
    {
//        申请状态（1为用户提交申请等待审核，2为管理员审核通过，3为审核不通过，4为志愿者取消申请。5位拒绝自愿者取消申请，6为同意自愿者取消申请。7为项目结束）默认为1）
        $status = [1 => '等待审核', 2 => '审核通过', 3 => '审核不通过', 4 => '志愿者提交取消申请', 5 => '拒绝自愿者取消申请', 6 => '同意自愿者取消申请',7=>'项目结束'];
        return ['val' => $value, 'text' => $status[$value]];
    }


    public function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc'])
    {
        $list = self::where($where)
            ->order($order)
            ->paginate($pageSize, false, ['query' => Request::get()]);
        return $list;
    }
}
